package com.zsy.petshop_01.controller;

import com.zsy.petshop_01.common.result.ResponseResult;
import com.zsy.petshop_01.model.vo.product.InsertVo;
import com.zsy.petshop_01.model.vo.product.UpdateVo;
import com.zsy.petshop_01.service.ProductService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "商品信息管理")
@RestController
@RequestMapping("/product")
public class ProductController {
    @Autowired
    ProductService productService;

    @ApiOperation("搜索所有商品信息")
    @GetMapping("/selectAll")
    public ResponseResult<?> selectAll() {
        return productService.selectAll();
    }

    @ApiOperation("搜索商品信息")
    @GetMapping("/selectByName")
    public ResponseResult<?> selectByName(@RequestParam(value = "name", required = false) String name) {
        return productService.selectByName(name);
    }

    @ApiOperation("添加商品信息")
    @PostMapping("/insert")
    public ResponseResult<?> insert(InsertVo insertVo) {
        return productService.insert(insertVo);
    }

    @ApiOperation("修改商品信息")
    @PostMapping("/update")
    public ResponseResult<?> update(UpdateVo updateVo) {
        return productService.update(updateVo);
    }

    @ApiOperation("删除商品信息")
    @PostMapping("/delete")
    public ResponseResult<?> delete(@RequestParam("id") Integer id) {
        return productService.delete(id);
    }
}
